package com.verisette.ncos.service.master.bizunit;

import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;

import org.corp.agi.common.exception.ProcessException;
import org.corp.agi.service.bean.ProcessContext;
import org.corp.agi.service.bizunit.CommonBusinessUnit;
import com.verisette.ncos.persistence.dao.UserGroupAuthorizationDAOImpl;
import com.verisette.ncos.persistence.domain.MasterUserGroup;

/**
 * {Description here}
 *
 * @author Thippawan Muangchu (Tip)
 * @since Mar 31, 2010 2:01:44 PM
 * @version 1.0.0
 * @see 
 */
public class LoadUserGroupBU extends CommonBusinessUnit {

	private Logger logger = Logger.getLogger(LoadUserGroupBU.class);
	
	//initial DAO
	private UserGroupAuthorizationDAOImpl userGroupAuthDAO;
	@Required
	@Autowired
	public void setUserGroupAuthorizationDAO(UserGroupAuthorizationDAOImpl userGroupAuthDAO) {
		this.userGroupAuthDAO = userGroupAuthDAO;
	}
	
	@Override
	public void execute(ProcessContext processContext) throws ProcessException {
		HashMap<String, String> userGroupMap = new HashMap<String, String>();
		List <MasterUserGroup> list = (List<MasterUserGroup>) userGroupAuthDAO.loadUserGroup();
		//loop get usgId, usgName put to hashmap
		for(int i=0;i<list.size();i++){
			userGroupMap.put(String.valueOf(list.get(i).getUsgId()), list.get(i).getUsgName());
		}
		processContext.setValueObject(userGroupMap);
	}

}
